package com.financing.wap.web.controller.api;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.financing.wap.common.ResultMap;
import com.financing.wap.dto.FpVideoHisDTO;
import com.financing.wap.service.IFpVideoHisService;
import com.financing.wap.util.DTOdateSetUtil;
import com.financing.wap.web.controller.BaseController;

@Controller("fpVideoHisController")
@RequestMapping("/api/fpVideoHis")
public class FpVideoHisController extends BaseController  { 

	private Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private IFpVideoHisService fpVideoHisService;
	
	
	@RequestMapping("/addFpVideoHis")
	@ResponseBody
	public ResultMap add(HttpServletRequest request, FpVideoHisDTO fpVideoHis){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("add fpVideoHis  begin .......");
			
			DTOdateSetUtil.setCreateInfo(fpVideoHis);
			DTOdateSetUtil.setUpdateInfo(fpVideoHis);
			
			int id = fpVideoHisService.insert(fpVideoHis);
			result.setAttribute("id", id);
			
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("add fpVideoHis list end .......");
		}catch(Exception e){
			log.error("add fpVideoHis error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
	
	@RequestMapping("/detailFpVideoHis")
	@ResponseBody
	public ResultMap detail(HttpServletRequest request, FpVideoHisDTO fpVideoHis){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("query detail fpVideoHis  begin .......");
			
			Integer id = fpVideoHis.getId();
			
			if(id==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			FpVideoHisDTO dto = fpVideoHisService.loadById(id);
			
			result.setAttribute("dto",dto);
			
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("query detail fpVideoHis  end .......");
		}catch(Exception e){
			log.error("query detail fpVideoHis error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
	@RequestMapping("/deleteFpVideoHis")
	@ResponseBody
	public ResultMap delete(HttpServletRequest request, FpVideoHisDTO fpVideoHis){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("delete fpVideoHis  begin .......");
			
			Integer id = fpVideoHis.getId();
			
			if(id==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			fpVideoHisService.delete(id);
			
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("delete fpVideoHis  end .......");
		}catch(Exception e){
			log.error("delete fpVideoHis error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
	@RequestMapping("/updateFpVideoHis")
	@ResponseBody
	public ResultMap update(HttpServletRequest request, FpVideoHisDTO fpVideoHis){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("update fpVideoHis  begin .......");
			
			Integer id = fpVideoHis.getId();
			
			if(id==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			DTOdateSetUtil.setUpdateInfo(fpVideoHis);
			
			fpVideoHisService.update(fpVideoHis);
			
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("update fpVideoHis list end .......");
		}catch(Exception e){
			log.error("update fpVideoHis error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
	@RequestMapping("/updateForceFpVideoHis")
	@ResponseBody
	public ResultMap updateForce(HttpServletRequest request, FpVideoHisDTO fpVideoHis){
		ResultMap result = new ResultMap();
		
		try{
			logger.info("updateForce fpVideoHis  begin .......");
			
			Integer id = fpVideoHis.getId();
			
			if(id==null){
				result.setStatusCode(ResultMap.STATUS_CODE_PARAMETERS_LOSE);
				result.setStatus(ResultMap.STATUS.FAILE);
				return result;
			}
			
			DTOdateSetUtil.setUpdateInfo(fpVideoHis);
			
			fpVideoHisService.updateForce(fpVideoHis);
			
			
			result.setStatusCode(ResultMap.STATUS_CODE_SUCCESS);
			result.setStatus(ResultMap.STATUS.SUCCESS);
			
			logger.info("updateForce fpVideoHis list end .......");
		}catch(Exception e){
			log.error("updateForce fpVideoHis error!",e);
			result.setStatus(ResultMap.STATUS.ERROR);
			result.setStatusCode(ResultMap.STATUS_CODE_SYS_EXCEPTION);
		}
		
		return result;
	}
	
}
